﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using YArchitech.Revit;

namespace HYRElectric.Equipment
{
	public class ElectricSwitchBoxesFilter : ISelectionFilter
	{
		bool ISelectionFilter.AllowElement(Element elem)
		{
			return ElectricSwitchBoxesFilter.IsValidSwitchBoxes(elem);
		}

		bool ISelectionFilter.AllowReference(Reference reference, XYZ position)
		{
			return false;
		}

		public static bool IsValidSwitchBoxes(Element elem)
		{
			try
			{
				if (elem is FamilyInstance && elem.Category.Id.IntegerValue == -2001040)
				{
					FamilySymbol familySymbol = elem.Document.GetElement(elem.GetTypeId()) as FamilySymbol;
					if (familySymbol != null && familySymbol.Family.get_Parameter(BuiltInParameter.FAMILY_CONTENT_PART_TYPE).AsInteger() == 14)
					{
						FamilyInstance elem2 = elem as FamilyInstance;
						Parameter parameter = elem2.GetParameter("宽度");
						Parameter parameter2 = elem2.GetParameter("高度");
						Parameter parameter3 = elem2.GetParameter("进深");
						return parameter != null && parameter2 != null && parameter3 != null;
					}
				}
			}
			catch (Exception)
			{
			}
			return false;
		}
	}
}
